<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button>添加li</button>
      <ul></ul>
    </div>

    <script>
      // 数组，数组有多少个元素，将来就要在ul里产生多少个li
      const list = ['张三', '李四', '王五']
      const ul = document.querySelector('#app>ul')
      for (let i = 0; i < list.length; i++) {
        const li = document.createElement('li')
        li.innerHTML = list[i]
        ul.appendChild(li)
      }

      document.querySelector('button').addEventListener('click', function () {
        const li = document.createElement('li')
        li.innerHTML = '赵六'
        ul.appendChild(li)
      })
    </script>
  </body>
</html>
